﻿using System;
using QueryResource.ViewModel;
using SimpleControlLibrary.Common;
using QueryResource.Common;

namespace SimpleControlLibrary.UI
{
    /// <summary>
    /// RegistDB.xaml 的交互逻辑
    /// </summary>
    public partial class RegistDB
    {
        RegistDBViewModel _viewModel;
        public RegistDB()
        {
            InitializeComponent();
        }
        private void WindowLoaded(object sender, EventArgs e)
        {
            _viewModel = new RegistDBViewModel();
            this.DataContext = _viewModel;
        }

        private void BtnSubmitClick(object sender, EventArgs e)
        {
            if (_viewModel.DataSource.DataBase == null ||
                _viewModel.DataSource.UserID == null ||
                _viewModel.DataSource.Server == null)
            {
                MessageBoxHelper.Show("数据库基本数据不完全，请查看");
                return;
            }
            if (_viewModel.Connection())
            {
                this.DialogResult = true;
            }
        }

        private void ButtonInfoClick(object sender, EventArgs e)
        {
            this.DialogResult = false;
        }

        private void DxWindowKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                BtnSubmitClick(null, null);
            }
            else if (e.Key == System.Windows.Input.Key.Escape)
            {
                ButtonInfoClick(null, null);
            }
        }
    }
}
